package ldh.text;

import com.jfoenix.controls.JFXDecorator;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import ldh.text.controller.MainController;
import ldh.text.util.FxmlNodeUtil;
import ldh.text.util.RegionUtil;
import ldh.text.util.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MainApp extends Application {

    private static final Logger LOGGER = LoggerFactory.getLogger(MainApp.class);

    public void start(Stage primaryStage) throws Exception {
        RegionUtil.setStage(primaryStage);

        Scene scene = new Scene(new Label(), 1000, 600);
        RegionUtil.setScene(scene);

        FxmlNodeUtil.FxmlNode<Pane, MainController> fxmlNode = FxmlNodeUtil.load(this.getClass().getResource("/fxml/Main.fxml"));
        JFXDecorator jfxDecorator = new JFXDecorator(primaryStage, fxmlNode.getNode());
        scene.setRoot(jfxDecorator);
        scene.getStylesheets().add(this.getClass().getResource("/css/main.css").toExternalForm());
        scene.getStylesheets().add(this.getClass().getResource("/css/text-area.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setTitle("Mini Text");

        primaryStage.setOnCloseRequest(e->{
            LOGGER.info("close!!!!!!!!!!!!!!!!!!!!!");
            fxmlNode.getController().close();
            ThreadPoolUtil.close();
            Platform.exit();
            System.exit(-1);
        });

        primaryStage.show();

        LOGGER.info("Mini Text start!!!!!!!!!!!!!!!!!!");
    }
}
